package DAO;

import Entities.BookTagEntity;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;

import java.util.*;

//标签
public class TagDao extends HibernateDaoSupport
{

    //返回标签名称数组
    public String[] getTags()
    {
        List<BookTagEntity> resultList = (List<BookTagEntity>) this.getHibernateTemplate().find("from BookTagEntity t where t.tagLevel=1");
        int numOfTags  = resultList.size();
        String [] tags = new String[105];
        for (int i=0; i<105; i++)
            tags[i] = resultList.get(i).getTagName();


        //把标签存入缓存
        CacheManager.getCacheManager("__DEFAULT__").getCache("DefaultCache").put(new Element("wholeTags",tags));

        return tags;
    }


}
